# -*-coding: Utf-8 -*-
# @File : db_hander .py
# author: Chimengmeng
# blog_url : https://www.cnblogs.com/dream-ze/
# Time：2023/6/10
import os

from conf import settings


def select(username):
    # 用户单独文件的路径
    user_path = os.path.join(settings.USER_DATA_PATH, f'{username}.txt')
    if os.path.exists(user_path):
        with open(user_path, 'r', encoding='utf8') as f:
            user_data = f.read()
            return user_data
    else:
        return None


def save(user_infos):
    username = user_infos.strip().split('|')[0]
    user_path = os.path.join(settings.USER_DATA_PATH, f'{username}.txt')
    with open(user_path, 'w', encoding='utf8') as f:
        f.write(user_infos)


if __name__ == '__main__':
    # select('admin')
    pass

